using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace iDev
{
    public class Startup
    {
        public IConfiguration Configuration { get; }
        public IHostingEnvironment Env { get; }
        public ILoggerFactory Logger { get; }

        public Startup(IConfiguration configuration, IHostingEnvironment env, ILoggerFactory logger)
        {
            Configuration = configuration;
            Env = env;
            Logger = logger;
        }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options => options.AddPolicy("cors", p => p.AllowAnyMethod().SetIsOriginAllowed(_ => true).AllowAnyHeader().AllowCredentials()));
            Adp.Startup.PlusConfigureServices(services, Configuration, Env, Logger);
            
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseCors("cors");
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/tcm/error");
            }
            app.UseStaticFiles();
            Adp.Startup.PlusConfigure(app, Configuration, env, Logger);
        }
    }
}
